package ${escapeKotlinIdentifiers(packageName)}.${escapeKotlinIdentifiers(viewModelPackage)}

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import cn.xuexuan.mvvm.extensions.addTo
import cn.xuexuan.mvvm.extensions.performOnBackOutOnMain
import cn.xuexuan.mvvm.net.*
import ${escapeKotlinIdentifiers(packageName)}.base.BaseViewModel
import ${escapeKotlinIdentifiers(packageName)}.data.DataManager
import ${escapeKotlinIdentifiers(packageName)}.model.bean.BaseModel
import ${escapeKotlinIdentifiers(packageName)}.model.bean.LoginBean
import ${escapeKotlinIdentifiers(packageName)}.model.bean.${modelClass}


/**
 * create by xuexuan
 * 来自薛瑄的自定义模板
 */
class ${viewModelClass}(dataManager: DataManager, scheduler: SchedulerProvider) : BaseViewModel(dataManager, scheduler) {

    var mSuccessStringLD: MutableLiveData<String> = MutableLiveData()
    var mFailStringLD: MutableLiveData<String> = MutableLiveData()
    var mErrorLD: MutableLiveData<NetError> = MutableLiveData()

    var mListLD: MutableLiveData<${modelClass}> = MutableLiveData()
	
    fun login(name:String,pwd:String) {
        setIsLoading(true)
        var loginBean = LoginBean(name,pwd)
        dataManager.httpService.login(loginBean)
            .compose<BaseModel<${modelClass}>>(XNet.getSingleTransformer())
            .performOnBackOutOnMain(scheduler)
            .subscribeWith(object : ApiSubscriber<BaseModel<${modelClass}>>() {
                override fun onFail(error: NetError?) {
                    //网络方面的错误
                    setIsLoading(false)
                    mErrorLD.value = error
                }

                override fun success(t: BaseModel<${modelClass}>) {
                    setIsLoading(false)
                    //业务的成功与否
                    if (t.success) {
                        mListLD.value = t.data
                    } else {
                        mFailStringLD.value = t.msg
                    }
                }
            })
            .addTo(compositeDisposable)
    }

 
}